package com.saya.model;

import com.google.appengine.api.datastore.Entity;
import com.google.appengine.api.datastore.Key;
import com.saya.utils.Constant;
import com.saya.utils.Utils;

public class User {
	 private String phoneNumber;
	  private String password;
	  private String deviceId;
	  private String email;
	  private String fullName;
	  private String address;

	  public String getPhoneNumber()
	  {
	    return this.phoneNumber;
	  }
	  public void setPhoneNumber(String phoneNumber) {
	    this.phoneNumber = phoneNumber;
	  }
	  public String getPassword() {
	    return this.password;
	  }
	  public void setPassword(String password) {
	    this.password = password;
	  }
	  public String getDeviceId() {
	    return this.deviceId;
	  }
	  public void setDeviceId(String deviceId) {
	    this.deviceId = deviceId;
	  }
	  public String getFullName() {
	    return this.fullName;
	  }
	  public void setFullName(String fullName) {
	    this.fullName = fullName;
	  }
	  public String getEmail() {
	    return this.email;
	  }
	  public void setEmail(String email) {
	    this.email = email;
	  }

	  public String getAddress() {
	    return this.address;
	  }
	  public void setAddress(String address) {
	    this.address = address;
	  }

	  public User(String phoneNumber, String password, String deviceId, String fullname, String email, String address) {
	    this.phoneNumber = phoneNumber;
	    this.password = password;
	    this.deviceId = deviceId;
	    this.fullName = fullname;
	    this.email = email;
	    this.address = address;
	  }

	  public User()
	  {
	  }

	  public Boolean CreateorUpdate(User user) {
	    Entity e = new Entity(Constant.USER_TABLE, user.getPhoneNumber());
	    e.setProperty(Constant.PHONE_NUMBER, user.getPhoneNumber());
	    e.setProperty(Constant.PASSWORD, user.getPassword());
	    e.setProperty(Constant.FULLNAME, user.getFullName());
	    e.setProperty(Constant.EMAIL, user.getEmail());
	    e.setProperty(Constant.DEVICEID, user.getDeviceId());
	    e.setProperty(Constant.ADDRESS, user.getAddress());
	    Key k = Utils.persistEntity(e);
	    if ((k != null) && (k.getName() != null) && (k.getName().equals(user.phoneNumber))) {
	      return Boolean.valueOf(true);
	    }
	    return Boolean.valueOf(false);
	  }

	  public User getUser(String phoneNumber)
	  {
	    Entity e = Utils.getEntity("User", phoneNumber);
	    if (e != null) {
	      User user = new User();
	      user.setPhoneNumber((String)e.getProperty(Constant.PHONE_NUMBER));
	      user.setPassword((String)e.getProperty(Constant.PASSWORD));
	      user.setFullName((String)e.getProperty(Constant.FULLNAME));
	      user.setEmail((String)e.getProperty(Constant.EMAIL));
	      user.setDeviceId((String)e.getProperty(Constant.DEVICEID));
	      user.setAddress((String)e.getProperty(Constant.ADDRESS));
	      return user;
	    }
	    return null;
	  }
}
